package com.springmvc.web.servlet.view;

import com.springmvc.web.servlet.View;
import com.springmvc.web.servlet.ViewResolver;

import java.util.Locale;


/**
 * 内部资源视图解析器实现类
 */
public class InternalResourceViewResolver implements ViewResolver {
    private String prefix;
    private String suffix;

    /**
     * 构造方法，初始化前缀和后缀
     */
    public InternalResourceViewResolver(String prefix, String suffix) {
        this.prefix = prefix;
        this.suffix = suffix;
    }

    public InternalResourceViewResolver() {
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    /**
     *  将逻辑视图名称和前缀、后缀拼接，然后返回一个View对象
     * @param viewName
     * @param locale
     * @return
     * @throws Exception
     */
    @Override
    public View resolveViewName(String viewName, Locale locale) throws Exception {
        return new InternalResourceView("text/html;charset=UTF-8", prefix + viewName + suffix);
    }
}
